package com.ymttest.database.sqlwapper;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.ProductImportDetail;
import com.ymttest.database.model.ProductImportTask;
import com.ymttest.database.model.ProductPacket;
import com.ymttest.utils.EnvSetup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProductImporterWapper {
    SqlManager manager;

    public ProductImporterWapper() {
        manager = new SqlManager("mysqlgodfreight" + EnvSetup.getEnv());
    }

    public ProductImportTask selectProductImportTaskByTaskId(int taskId) {
        List<ProductImportTask> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.ProductImporterMapper.selectProductImportTaskByTaskId",
                        taskId);
        manager.commit();
        return result.get(0);
    }

    public int selectTotalNumBySellerId(int sellerId) {
        List<Integer> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.ProductImporterMapper.selectTotalNumBySellerId",
                        sellerId);
        manager.commit();
        return result.get(0);
    }

    public List<ProductImportDetail> selectProductImportDetailByTaskIdWithIsSuccess(int taskId,boolean isSuccess) {
        Map m = new HashMap<>();
        m.put("taskId",taskId);
        int success = 1;
        if(!isSuccess){
            success=0;
        }
        m.put("success",success);
        List<ProductImportDetail> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.ProductImporterMapper.selectProductImportDetailByTaskIdWithIsSuccess",
                        m);
        manager.commit();
        if (result!=null){
            return result;
        }else {
            return null;
        }
    }

    public List<ProductPacket> selectProductPacketByTaskId(int taskId) {
        List<ProductPacket> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.ProductImporterMapper.selectProductPacketByTaskId",
                        taskId);
        manager.commit();
        return result;
    }

    public List<ProductImportDetail> selectProductImportDetailByTaskId(int taskId) {
        List<ProductImportDetail> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.ProductImporterMapper.selectProductImportDetailByTaskId",
                        taskId);
        manager.commit();
        return result;
    }

    public static void main(String[] args) {
        ProductImporterWapper productImporterWapper = new ProductImporterWapper();
    }
}
